// 自动生成的菜单配置文件
// 生成时间: 2025-06-30T23:17:09.244457
// 此文件由动态菜单系统自动生成，请勿手动修改

export interface MenuItem {
  id: string | number
  name: string
  path: string
  icon: string
  order: number
  permission_code?: string
  children?: MenuItem[]
}

export const STATIC_MENUS: MenuItem[] = [
    {
      id: '70',
      name: '仪表盘',
      path: '/dashboard',
      icon: 'fa fa-dashboard',
      order: 1,
      permission_code: '仪表盘.view',
    children: []
    },    {
      id: '71',
      name: 'CMDB资产管理',
      path: '/cmdb',
      icon: 'fa fa-database',
      order: 2,
      permission_code: 'cmdb资产管理.view',
    children: [
      {
        id: '77',
        name: '主机管理',
        path: '/cmdb/hosts',
        icon: 'fa fa-server',
        order: 1,
        permission_code: '主机管理.view',
      children: []
      },
      {
        id: '78',
        name: '连接主机',
        path: '/cmdb/connections',
        icon: 'fa fa-terminal',
        order: 2,
        permission_code: '连接主机.view',
      children: []
      },
      {
        id: '79',
        name: '主机组管理',
        path: '/cmdb/hostgroups',
        icon: 'fa fa-object-group',
        order: 3,
        permission_code: '主机组管理.view',
      children: []
      },
      {
        id: '80',
        name: '主机类型管理',
        path: '/cmdb/hosttypes',
        icon: 'fa fa-tags',
        order: 4,
        permission_code: '主机类型管理.view',
      children: []
      }
    ]
    },    {
      id: '72',
      name: '用户资源页面',
      path: '/user',
      icon: 'fa fa-users',
      order: 4,
      permission_code: '用户资源页面.view',
    children: [
      {
        id: '81',
        name: '用户管理',
        path: '/user/usermanagement',
        icon: 'fa fa-user',
        order: 1,
        permission_code: '用户管理.view',
      children: []
      },
      {
        id: '82',
        name: '用户组管理',
        path: '/cmdb/user/groups',
        icon: 'fa fa-users',
        order: 2,
        permission_code: '用户组管理.view',
      children: []
      },
      {
        id: '83',
        name: '角色管理',
        path: '/cmdb/user/roles',
        icon: 'fa fa-user-tag',
        order: 3,
        permission_code: '角色管理.view',
      children: []
      },
      {
        id: '84',
        name: '菜单权限管理',
        path: '/cmdb/user/menu-permission',
        icon: 'fa fa-key',
        order: 4,
        permission_code: '菜单权限管理.view',
      children: []
      }
    ]
    },    {
      id: '73',
      name: 'Ansible管理',
      path: '/ansible',
      icon: 'fa fa-tasks',
      order: 5,
      permission_code: 'ansible管理.view',
    children: [
      {
        id: '85',
        name: '配置管理',
        path: '/ansible/config',
        icon: 'fa fa-cogs',
        order: 1,
        permission_code: '配置管理.view',
      children: []
      },
      {
        id: '86',
        name: 'Inventory管理',
        path: '/ansible/inventory',
        icon: 'fa fa-list-alt',
        order: 2,
        permission_code: 'inventory管理.view',
      children: []
      },
      {
        id: '87',
        name: 'Ad-hoc执行',
        path: '/ansible/adhoc',
        icon: 'fa fa-play',
        order: 3,
        permission_code: 'ad-hoc执行.view',
      children: []
      },
      {
        id: '88',
        name: 'Playbook执行',
        path: '/ansible/playbook',
        icon: 'fa fa-play-circle',
        order: 4,
        permission_code: 'playbook执行.view',
      children: []
      },
      {
        id: '89',
        name: '凭据管理',
        path: '/ansible/credentials',
        icon: 'fa fa-shield',
        order: 5,
        permission_code: '凭据管理.view',
      children: []
      },

    ]
    },    {
      id: '129',
      name: 'Zabbix管理',
      path: '/zabbix',
      icon: 'fa fa-eye',
      order: 6,
      permission_code: 'zabbix管理.view',
    children: [
      {
        id: '130',
        name: '服务器配置',
        path: '/zabbix/servers',
        icon: 'fa fa-server',
        order: 1,
        permission_code: '服务器配置.view',
      children: []
      },
      {
        id: '131',
        name: '监控仪表板',
        path: '/zabbix/dashboard',
        icon: 'fa fa-dashboard',
        order: 2,
        permission_code: '监控仪表板.view',
      children: []
      },
      {
        id: '132',
        name: '主机监控',
        path: '/zabbix/hosts',
        icon: 'fa fa-desktop',
        order: 3,
        permission_code: '主机监控.view',
      children: []
      },
      {
        id: '133',
        name: '告警管理',
        path: '/zabbix/alerts',
        icon: 'fa fa-bell',
        order: 4,
        permission_code: '告警管理.view',
      children: []
      },
      {
        id: '134',
        name: '模板管理',
        path: '/zabbix/templates',
        icon: 'fa fa-file-code',
        order: 5,
        permission_code: '模板管理.view',
      children: []
      },
      {
        id: '135',
        name: '监控项管理',
        path: '/zabbix/items',
        icon: 'fa fa-list-alt',
        order: 6,
        permission_code: '监控项管理.view',
      children: []
      }
    ]
    },    {
      id: '136',
      name: 'CICD管理',
      path: '/devops',
      icon: 'fa fa-code-branch',
      order: 6,
      permission_code: 'cicd管理.view',
    children: [
      {
        id: '137',
        name: 'GitLab管理',
        path: '/devops/gitlab',
        icon: 'fa fa-gitlab',
        order: 1,
        permission_code: 'gitlab管理.view',
      children: [
        {
          id: '138',
          name: '服务器配置',
          path: '/devops/gitlab/servers',
          icon: 'fa fa-server',
          order: 1,
          permission_code: 'gitlab服务器.view',
        children: []
        },
        {
          id: '139',
          name: '项目管理',
          path: '/devops/gitlab/projects',
          icon: 'fa fa-folder',
          order: 2,
          permission_code: 'gitlab项目.view',
        children: []
        },
        {
          id: '140',
          name: '用户管理',
          path: '/devops/gitlab/users',
          icon: 'fa fa-users',
          order: 3,
          permission_code: 'gitlab用户.view',
        children: []
        }
      ]
      },
      {
        id: '141',
        name: 'Jenkins管理',
        path: '/devops/jenkins',
        icon: 'fa fa-cogs',
        order: 2,
        permission_code: 'jenkins管理.view',
      children: [
        {
          id: '142',
          name: '服务器配置',
          path: '/devops/jenkins/servers',
          icon: 'fa fa-server',
          order: 1,
          permission_code: 'jenkins服务器.view',
        children: []
        },
        {
          id: '143',
          name: '项目管理',
          path: '/devops/jenkins/jobs',
          icon: 'fa fa-tasks',
          order: 2,
          permission_code: 'jenkins项目.view',
        children: []
        }
      ]
      },
      {
        id: '144',
        name: '操作时间线',
        path: '/devops/timeline',
        icon: 'fa fa-history',
        order: 3,
        permission_code: 'devops时间线.view',
      children: []
      }
    ]
    },    {
      id: '147',
      name: 'Docker管理',
      path: '/docker',
      icon: 'fa fa-docker',
      order: 7,
      permission_code: 'docker管理.view',
    children: [
      {
        id: '148',
        name: '服务器配置',
        path: '/docker/servers',
        icon: 'fa fa-server',
        order: 1,
        permission_code: 'docker服务器.view',
      children: []
      },
      {
        id: '149',
        name: '容器管理',
        path: '/docker/containers',
        icon: 'fa fa-cube',
        order: 2,
        permission_code: 'docker容器.view',
      children: []
      },
      {
        id: '150',
        name: '镜像管理',
        path: '/docker/images',
        icon: 'fa fa-layer-group',
        order: 3,
        permission_code: 'docker镜像.view',
      children: []
      },
      {
        id: '151',
        name: '网络管理',
        path: '/docker/networks',
        icon: 'fa fa-network-wired',
        order: 4,
        permission_code: 'docker网络.view',
      children: []
      },
      {
        id: '152',
        name: '数据卷管理',
        path: '/docker/volumes',
        icon: 'fa fa-hdd',
        order: 5,
        permission_code: 'docker数据卷.view',
      children: []
      },
      {
        id: '154',
        name: '容器监控',
        path: '/docker/monitoring',
        icon: 'fa fa-chart-line',
        order: 6,
        permission_code: 'docker容器监控.view',
      children: []
      }
    ]
    },    {
      id: '155',
      name: '镜像仓库管理',
      path: '/harbor',
      icon: 'fa fa-ship',
      order: 8,
      permission_code: '镜像仓库管理.view',
    children: [
      {
        id: '156',
        name: 'Harbor镜像仓库配置',
        path: '/docker/registries',
        icon: 'fa fa-archive',
        order: 1,
        permission_code: 'harbor镜像仓库配置.view',
      children: []
      },
      {
        id: '157',
        name: 'Harbor项目管理',
        path: '/harbor/projects',
        icon: 'fa fa-folder',
        order: 2,
        permission_code: 'harbor项目管理.view',
      children: []
      },
      {
        id: '158',
        name: 'Harbor镜像管理',
        path: '/harbor/images',
        icon: 'fa fa-layer-group',
        order: 3,
        permission_code: 'harbor镜像管理.view',
      children: []
      },
      {
        id: '159',
        name: 'Harbor审计日志',
        path: '/harbor/audit-logs',
        icon: 'fa fa-file-text',
        order: 4,
        permission_code: 'harbor审计日志.view',
      children: []
      }
    ]
    },    {
      id: '74',
      name: '历史记录',
      path: '/history',
      icon: 'fa fa-history',
      order: 9,
      permission_code: '历史记录.view',
    children: [
      {
        id: '91',
        name: 'SSH日志审计',
        path: '/history/ssh-audit',
        icon: 'fa fa-terminal',
        order: 1,
        permission_code: 'ssh日志审计.view',
      children: []
      },
      {
        id: '92',
        name: 'Ansible日志审计',
        path: '/history/ansible-audit',
        icon: 'fa fa-tasks',
        order: 2,
        permission_code: 'ansible日志审计.view',
      children: []
      },
      {
        id: '145',
        name: 'GitLab集成历史',
        path: '/history/gitlab-audit',
        icon: 'fa fa-gitlab',
        order: 3,
        permission_code: 'gitlab集成历史.view',
      children: []
      },
      {
        id: '146',
        name: 'Jenkins构建历史',
        path: '/history/jenkins-builds-audit',
        icon: 'fa fa-cogs',
        order: 4,
        permission_code: 'jenkins构建历史.view',
      children: []
      },
      {
        id: '93',
        name: 'SQL日志审计',
        path: '/history/sql-audit',
        icon: 'fa fa-database',
        order: 5,
        permission_code: 'sql日志审计.view',
      children: []
      }
    ]
    },    {
      id: '76',
      name: '系统管理',
      path: '/system',
      icon: 'fa fa-cogs',
      order: 10,
      permission_code: '系统管理.view',
    children: [
      {
        id: '94',
        name: '菜单管理',
        path: '/system/menu-management',
        icon: 'fa fa-list',
        order: 1,
        permission_code: '菜单管理.view',
      children: []
      },
      {
        id: '75',
        name: '监控中心',
        path: '/system/monitoring',
        icon: 'fa fa-line-chart',
        order: 8,
        permission_code: '监控中心.view',
      children: []
      },
      {
        id: '115',
        name: '系统备份',
        path: '/system/系统备份',
        icon: 'fa fa-database',
        order: 100,
        permission_code: '系统备份.view',
      children: []
      }
    ]
    }
]

// 权限代码映射
export const PERMISSION_CODES = {
  '仪表盘.view': '仪表盘',  'cmdb资产管理.view': 'CMDB资产管理',  '主机管理.view': '主机管理',  '连接主机.view': '连接主机',  '主机组管理.view': '主机组管理',  '主机类型管理.view': '主机类型管理',  '用户资源页面.view': '用户资源页面',  '用户管理.view': '用户管理',  '用户组管理.view': '用户组管理',  '角色管理.view': '角色管理',  '菜单权限管理.view': '菜单权限管理',  'ansible管理.view': 'Ansible管理',  '配置管理.view': '配置管理',  'inventory管理.view': 'Inventory管理',  'ad-hoc执行.view': 'Ad-hoc执行',  'playbook执行.view': 'Playbook执行',  '凭据管理.view': '凭据管理',  'zabbix管理.view': 'Zabbix管理',  '服务器配置.view': '服务器配置',  '监控仪表板.view': '监控仪表板',  '主机监控.view': '主机监控',  '告警管理.view': '告警管理',  '模板管理.view': '模板管理',  '监控项管理.view': '监控项管理',  'cicd管理.view': 'CICD管理',  'gitlab管理.view': 'GitLab管理',  'gitlab服务器.view': 'GitLab服务器配置',  'gitlab项目.view': 'GitLab项目管理',  'gitlab用户.view': 'GitLab用户管理',  'jenkins管理.view': 'Jenkins管理',  'jenkins服务器.view': 'Jenkins服务器配置',  'jenkins项目.view': 'Jenkins项目管理',  'devops时间线.view': 'DevOps操作时间线',  'docker管理.view': 'Docker管理',  'docker服务器.view': 'Docker服务器配置',  'docker容器.view': 'Docker容器管理',  'docker镜像.view': 'Docker镜像管理',  'docker网络.view': 'Docker网络管理',  'docker数据卷.view': 'Docker数据卷管理',  'docker容器监控.view': 'Docker容器监控',  '镜像仓库管理.view': '镜像仓库管理',  'harbor镜像仓库配置.view': 'Harbor镜像仓库配置',  'harbor项目管理.view': 'Harbor项目管理',  'harbor镜像管理.view': 'Harbor镜像管理',  'harbor审计日志.view': 'Harbor审计日志',  '历史记录.view': '历史记录',  'ssh日志审计.view': 'SSH日志审计',  'ansible日志审计.view': 'Ansible日志审计',  'gitlab集成历史.view': 'GitLab集成历史',  'jenkins构建历史.view': 'Jenkins构建历史',  'sql日志审计.view': 'SQL日志审计',  '系统管理.view': '系统管理',  '菜单管理.view': '菜单管理',  '监控中心.view': '监控中心',  '系统备份.view': '系统备份'
}

/**
 * 根据用户权限过滤菜单
 * @param userPermissions 用户权限列表
 * @returns 过滤后的菜单列表
 */
export function getFilteredMenus(userPermissions: string[]): MenuItem[] {
  // 如果没有权限，返回空数组
  if (!userPermissions || userPermissions.length === 0) {
    return []
  }

  // 递归过滤菜单的函数
  function filterMenuItems(menus: MenuItem[]): MenuItem[] {
    return menus.filter(menu => {
      // 检查当前菜单是否有权限
      const hasPermission = !menu.permission_code ||
                           userPermissions.includes(menu.permission_code) ||
                           userPermissions.includes('*') ||
                           userPermissions.includes('admin')

      // 如果有子菜单，递归过滤子菜单
      if (menu.children && menu.children.length > 0) {
        const filteredChildren = filterMenuItems(menu.children)

        // 如果当前菜单有权限，或者有可访问的子菜单，则保留
        if (hasPermission || filteredChildren.length > 0) {
          return {
            ...menu,
            children: filteredChildren
          }
        }
        return false
      }

      // 叶子节点，直接根据权限判断
      return hasPermission
    }).map(menu => {
      // 确保返回的菜单有正确的children属性
      if (menu.children && menu.children.length > 0) {
        return {
          ...menu,
          children: filterMenuItems(menu.children)
        }
      }
      return menu
    })
  }

  // 过滤并排序菜单
  const filteredMenus = filterMenuItems(STATIC_MENUS)

  // 按order字段排序
  return filteredMenus.sort((a, b) => (a.order || 0) - (b.order || 0))
}

export default STATIC_MENUS
